<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资管客户还款管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="insCstSettleNoCalc_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">资方支付表号</div>
            <div class="field">
                ${insCstRepaySettleVO.paySchNo}
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">提前还款本金</div>
            <div class="field">
                <input name="repayCapAmt" id="repayCapAmt" type="text" class="ui-textbox" value="">
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">提前还款利息</div>
            <div class="field">
                <input name="repayIntrAmt" id="repayIntrAmt" type="text" class="ui-textbox" value="">
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">提前还款手续费</div>
            <div class="field">
                <input name="repaySvcFeeAmt" id="repaySvcFeeAmt" type="text" class="ui-textbox" value="">
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">提前还款总金额</div>
            <div class="field">
                <input name="repayTtlAmt" id="repayTtlAmt" type="text" class="ui-textbox" value="">
            </div>
            <span class="requiredSymbol">*</span>
        </div>
        <div class="fieldBox col_100">
            <div class="label">还款资金来源</div>
            <div class="field">
                <input name="accTypCd" id="accTypCd" data-value="" placeholder="请选择" ltype="combobox"
                       validate="{required:true,select:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
    </div>
</form>
<script>
    var form = null;
    $(function () {
        form = $("#insCstSettleNoCalc_form").ligerForm({
            validate: true
        });

        $("#accTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("accTypCd").setData(${accTypCdList});

        if ("${errorFlag}" == "1") {
            $("#errorMsgDiv").show();
        }

        var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
        //按钮在页面外的Dialog里，给Dialog绑定事件 （onOk 和 onCancel）
        frameElement.dialog.onOk = function () {
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            //金额正则表达式
            var fix_amountTest = /^(([1-9]\d*)|\d)(\.\d{1,2})?$/;
            //提前还款本金
            var repayCapAmt = $("#repayCapAmt").val();
            //提前还款利息
            var repayIntrAmt = $("#repayIntrAmt").val();
            //提前还款手续费
            var repaySvcFeeAmt = $("#repaySvcFeeAmt").val();
            //提前还款总金额
            var repayTtlAmt = $("#repayTtlAmt").val();
            if (!fix_amountTest.test(repayCapAmt)) {
                $.ligerDialog.SQalert({content: "提前还款本金格式异常", SQ_type: "error", SQ_showButtons: true});
                return false;
            }
            if (!fix_amountTest.test(repayIntrAmt)) {
                $.ligerDialog.SQalert({content: "提前还款利息格式异常", SQ_type: "error", SQ_showButtons: true});
                return false;
            }
            if (!fix_amountTest.test(repayTtlAmt)) {
                $.ligerDialog.SQalert({content: "提前还款总金额格式异常", SQ_type: "error", SQ_showButtons: true});
                return false;
            }

            frameElement.dialog.disabledBtns();
            frameElement.dialog.mask();

            var accTypCd = liger.get("accTypCd").selectedValue;
            var _url = '<%=path%>/repay/insCstRepaySettle/repayOrsettle.do';
            var data = {
                "id": "${insCstRepaySettleVO.id}",
                "prjId": "${insCstRepaySettleVO.prjId}",
                "insId": "${insCstRepaySettleVO.insId}",
                "insCode": "${insCstRepaySettleVO.insCode}",
                "type": "settle",
                "accTypCd": accTypCd,
                "repayCapAmt": repayCapAmt,
                "repayIntrAmt": repayIntrAmt,
                "repaySvcFeeAmt": repaySvcFeeAmt,
                "repayTtlAmt": repayTtlAmt
            };
            var wait_dialog;

            $.ligerDialog.confirm("是否确定提前还款？", function (flag) {
                if (flag == false) return;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: data,
                    url: _url,
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success", SQ_showButtons: true});
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error", SQ_showButtons: true});
                        }
                    }
                });
            });
        }

        frameElement.dialog.onCancel = function () {
            frameElement.dialog.hide();
        };
    });
</script>
</body>
</html>
